﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Special_Item
{
    public partial class Pro_User_Password : Form
    {
        public Pro_User_Password()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 修改单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_con_Click(object sender, EventArgs e)
        {
            //当前窗体原密码
            var RawPwd = this.txt_RawPwd.Text;
            //当前窗体新密码
            var NewPwd = this.txt_NewPwd.Text;
            //当前窗体确定密码
            var ConPwd = this.txt_ConPwd.Text;
            //判断是否为null和两次输入密码是否一致
            if (string.IsNullOrWhiteSpace(RawPwd))
            {
                MessageBox.Show("原密码不能为空！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.txt_RawPwd.Focus();
            }
            else if (string.IsNullOrWhiteSpace(NewPwd))
            {
                MessageBox.Show("新密码不能为空！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_NewPwd.Focus();
            }
            else if (RawPwd == NewPwd)
            {
                MessageBox.Show("新密码不能和原密码一样！","提示信息",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
                this.txt_NewPwd.Focus();
            }
           else if(string.IsNullOrWhiteSpace(ConPwd))
            {
                MessageBox.Show("确定密码不能为空！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_ConPwd.Focus();
            }
             else if(!this.txt_NewPwd.Text.Equals(ConPwd))
            {
                MessageBox.Show("两次密码不一致！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_ConPwd.Focus();
            }
            else
            {
                //var stu = @"Data Source=.; Initial Catalog=Training_Project; Uid=hll; Pwd=123;";
                //var conn = new SqlConnection(stu);
                //try
                //{
                //    conn.Open();
                //    //判断输入原密码是否正确
                //    var sql = string.Format("select Passward from Stu_Login where Passward='{0}'", RawPwd);
                //    SqlCommand comm = new SqlCommand(sql, conn);
                //    object obj = comm.ExecuteScalar();
                //    if (!RawPwd.Equals(obj))
                //    {
                //        MessageBox.Show("你输入的原密码错误！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                //        this.txt_RawPwd.Focus();
                //    }
                //    else
                //    {
                //        //更改密码数据库更新
                //        var sql1 = string.Format("update Stu_Login set Passward='{0}' where Passward='{1}'", ConPwd, RawPwd);
                //        SqlCommand comm1 = new SqlCommand(sql1, conn);
                //        int num = comm1.ExecuteNonQuery();
                //        if (num > 0)
                //        {
                //            //弹出修改成功窗体
                //            Pro_User_Password1 pwd = new Pro_User_Password1();
                //            pwd.Show();
                //            this.Hide();
                //        }
                //        else
                //        {
                //            MessageBox.Show("修改失败！");
                //            this.txt_RawPwd.Focus();
                //        }
                //    }
                //}
                //catch (Exception)
                //{
                //    //报错弹框
                //    MessageBox.Show("服务器错误,请联系管理员");
                //}
                //finally
                //{
                //    conn.Close();
                //}  
            } 
        }
    }
}
